import Vobj from "./Vobj";
import Gobj from "./Gobj";
import GBullet from "./GBullet";
import GameWx from "../GameWx";

export default class VBullet extends Vobj {
    constructor() {
        super();
        this.graphics.drawCircle(0,0,10,"#00ff00");
    }

    init(o: Gobj) {
        super.init(o);
        var b = o as GBullet;
        if (this.isUP(o)) { //1 == 房主            
            this.x = this.sx - b.x;
            this.y = this.sy + b.y;
        } else {            
            this.x = this.sx + b.x;
            this.y = this.sy - b.y;
        }

        if(o.pid!=1){
            this.graphics.clear();
            this.graphics.drawCircle(0,0,10,"#0000ff");
        }
    }

    efe(o: Gobj, lf: number, fms: number) { 
        var b = o as GBullet;
        var xx =  b.tx - b.x ;
        var yy =  b.ty - b.y ;                
        var r = Math.atan2(yy, xx);
        xx = b.x + Math.cos(r)*b.z;
        yy = b.y + Math.sin(r)*b.z;

        // this.x = this.sx + xx;
        // this.y = this.sy - yy;

        if (this.isUP(o)) { //1 == 房主
            this.x = this.sx - xx;
            this.y = this.sy + yy;
        }else{    
            this.x = this.sx + xx;
            this.y = this.sy - yy;
        }
    }

    destory() {
        this.removeSelf();
    }
}